home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / DECL_EX.BAS < prev    next >
BASIC Source File  |  1988-09-17  |  764b  |  36 lines

  1. '
  2. ' *** DECL_EX.BAS - DECLARE statement programming example
  3. '
  4. ' Generate 20 random numbers, store them in an array, and
  5. ' sort. The sort subprogram is called without the CALL keyword.
  6. DECLARE SUB Sort(A(1) AS SINGLE, N AS INTEGER)
  7. DIM Array1(1 TO 20)
  8.  
  9. ' Generate 20 random numbers.
  10. RANDOMIZE TIMER
  11. FOR I=1 TO 20
  12.    Array1(I)=RND
  13. NEXT I
  14.  
  15. ' Sort the array and call Sort without the CALL keyword.
  16. ' Notice the absence of parentheses around the arguments in
  17. ' the call to Sort.
  18. Sort Array1(), 20%
  19.  
  20. ' Print the sorted array.
  21. FOR I=1 TO 20
  22.    PRINT Array1(I)
  23. NEXT I
  24. END
  25.  
  26. ' Sort subroutine.
  27. SUB Sort(A(1), N%) STATIC
  28.  
  29.    FOR I= 1 TO N%-1
  30.       FOR J=I+1 TO N%
  31.          IF A(I)>A(J) THEN SWAP A(I), A(J)
  32.       NEXT J
  33.    NEXT I
  34.  
  35. END SUB
  36.